package com.example.blog.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author ganggang
 * @version 1.0
 * @date 2022/2/12 10:15 上午
 */
@RestController
public class SessionController {
    @GetMapping("/create_session")
    public String createSession(HttpServletRequest request){
        HttpSession session = request.getSession();
        session.setAttribute("user",1);
        return "";
    }

    @GetMapping("/get_session")
    public String getSession(HttpServletRequest request){
        Object user = request.getSession().getAttribute("user");
        System.out.println(user);
        System.out.println(request.getSession().getId());
        return "";
    }
}
